import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';

// Get __dirname in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const resolve = (dir) => {
  return path.join(__dirname, dir);
};

const Timestamp = new Date().getTime();
const VERSION = `rqhaiyun_${Timestamp}`;

// Read JSON file using ES module syntax
const configPath = resolve("../../public/version.json");
const configJSON = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const configFile = path.resolve(__dirname, "../../public/version.json");

fs.writeFileSync(
  configFile,
  JSON.stringify(
    {
      ...configJSON,
      version: VERSION,
    },
    null,
    2
  )
);
